/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author spthanh
 */
public class Scrollable_Pstmt {
    public static void main(String[] args){
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks", "sa", "123");

            String query = "SELECT * FROM Person.Address WHERE City  LIKE ?";
            //Prepare Statement
            PreparedStatement pstmt =  con.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            //String inputParam = "London";
            pstmt.setString(1,"%London%");
            pstmt.setFetchSize(10);
            //Get result set
            ResultSet rs = pstmt.executeQuery();
            //Traverse the result set
            
            while(rs.next()){
                System.out.println("Address Line 1:" + rs.getString("AddressLine1"));
                System.out.println("AddressID:" + rs.getInt("AddressID"));
                System.out.println("City:" + rs.getString("City"));
            }


        }catch(Exception e){

        }
    }
}
